﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace GeoSketch2.Core
{
    public class AutoCadIndexedColor
    {
        public byte ACI;
        public byte R, G, B;

        public AutoCadIndexedColor(byte ACI, byte R, byte G, byte B)
        {
            this.ACI = ACI;
            this.R = R;
            this.G = G;
            this.B = B;
        }

        public static AutoCadIndexedColor GetNearestAutoCadColor(Color Color)
        {
            return GetNearestAutoCadColor(Color, ACITable);
        }

        public static AutoCadIndexedColor GetNearestAutoCadColor(Color Color, AutoCadIndexedColor[] AutoCadColors)
        {
            Point3D64D ColorToFind = new Point3D64D(Color.R, Color.G, Color.B);
            double MinDistance = ColorToFind.Distance3D(AutoCadColors[0].ColorCoordinates), TempDistance;
            AutoCadIndexedColor ColorFound = AutoCadColors[0];

            for (int i = 1; i < AutoCadColors.Length; i++)
            {
                TempDistance = ColorToFind.Distance3D(AutoCadColors[i].ColorCoordinates);

                if (TempDistance < MinDistance)
                {
                    MinDistance = TempDistance;
                    ColorFound = AutoCadColors[i];
                }
            }

            return ColorFound;
        }

        public static AutoCadIndexedColor[] ACITable
        {
            get
            {
                return new AutoCadIndexedColor[]{
                    new AutoCadIndexedColor(7,0,0,0),
new AutoCadIndexedColor(1,255,0,0),
new AutoCadIndexedColor(2,255,255,0),
new AutoCadIndexedColor(3,0,255,0),
new AutoCadIndexedColor(4,0,255,255),
new AutoCadIndexedColor(5,0,0,255),
new AutoCadIndexedColor(6,255,0,255),
new AutoCadIndexedColor(7,255,255,255),
new AutoCadIndexedColor(8,65,65,65),
new AutoCadIndexedColor(9,128,128,128),
new AutoCadIndexedColor(10,255,0,0),
new AutoCadIndexedColor(11,255,170,170),
new AutoCadIndexedColor(12,189,0,0),
new AutoCadIndexedColor(13,189,126,126),
new AutoCadIndexedColor(14,129,0,0),
new AutoCadIndexedColor(15,129,86,86),
new AutoCadIndexedColor(16,104,0,0),
new AutoCadIndexedColor(17,104,69,69),
new AutoCadIndexedColor(18,79,0,0),
new AutoCadIndexedColor(19,79,53,53),
new AutoCadIndexedColor(20,255,63,0),
new AutoCadIndexedColor(21,255,191,170),
new AutoCadIndexedColor(22,189,46,0),
new AutoCadIndexedColor(23,189,141,126),
new AutoCadIndexedColor(24,129,31,0),
new AutoCadIndexedColor(25,129,96,86),
new AutoCadIndexedColor(26,104,25,0),
new AutoCadIndexedColor(27,104,78,69),
new AutoCadIndexedColor(28,79,19,0),
new AutoCadIndexedColor(29,79,59,53),
new AutoCadIndexedColor(30,255,127,0),
new AutoCadIndexedColor(31,255,212,170),
new AutoCadIndexedColor(32,189,94,0),
new AutoCadIndexedColor(33,189,157,126),
new AutoCadIndexedColor(34,129,64,0),
new AutoCadIndexedColor(35,129,107,86),
new AutoCadIndexedColor(36,104,52,0),
new AutoCadIndexedColor(37,104,86,69),
new AutoCadIndexedColor(38,79,39,0),
new AutoCadIndexedColor(39,79,66,53),
new AutoCadIndexedColor(40,255,191,0),
new AutoCadIndexedColor(41,255,234,170),
new AutoCadIndexedColor(42,189,141,0),
new AutoCadIndexedColor(43,189,173,126),
new AutoCadIndexedColor(44,129,96,0),
new AutoCadIndexedColor(45,129,118,86),
new AutoCadIndexedColor(46,104,78,0),
new AutoCadIndexedColor(47,104,95,69),
new AutoCadIndexedColor(48,79,59,0),
new AutoCadIndexedColor(49,79,73,53),
new AutoCadIndexedColor(50,255,255,0),
new AutoCadIndexedColor(51,255,255,170),
new AutoCadIndexedColor(52,189,189,0),
new AutoCadIndexedColor(53,189,189,126),
new AutoCadIndexedColor(54,129,129,0),
new AutoCadIndexedColor(55,129,129,86),
new AutoCadIndexedColor(56,104,104,0),
new AutoCadIndexedColor(57,104,104,69),
new AutoCadIndexedColor(58,79,79,0),
new AutoCadIndexedColor(59,79,79,53),
new AutoCadIndexedColor(60,191,255,0),
new AutoCadIndexedColor(61,234,255,170),
new AutoCadIndexedColor(62,141,189,0),
new AutoCadIndexedColor(63,173,189,126),
new AutoCadIndexedColor(64,96,129,0),
new AutoCadIndexedColor(65,118,129,86),
new AutoCadIndexedColor(66,78,104,0),
new AutoCadIndexedColor(67,95,104,69),
new AutoCadIndexedColor(68,59,79,0),
new AutoCadIndexedColor(69,73,79,53),
new AutoCadIndexedColor(70,127,255,0),
new AutoCadIndexedColor(71,212,255,170),
new AutoCadIndexedColor(72,94,189,0),
new AutoCadIndexedColor(73,157,189,126),
new AutoCadIndexedColor(74,64,129,0),
new AutoCadIndexedColor(75,107,129,86),
new AutoCadIndexedColor(76,52,104,0),
new AutoCadIndexedColor(77,86,104,69),
new AutoCadIndexedColor(78,39,79,0),
new AutoCadIndexedColor(79,66,79,53),
new AutoCadIndexedColor(80,63,255,0),
new AutoCadIndexedColor(81,191,255,170),
new AutoCadIndexedColor(82,46,189,0),
new AutoCadIndexedColor(83,141,189,126),
new AutoCadIndexedColor(84,31,129,0),
new AutoCadIndexedColor(85,96,129,86),
new AutoCadIndexedColor(86,25,104,0),
new AutoCadIndexedColor(87,78,104,69),
new AutoCadIndexedColor(88,19,79,0),
new AutoCadIndexedColor(89,59,79,53),
new AutoCadIndexedColor(90,0,255,0),
new AutoCadIndexedColor(91,170,255,170),
new AutoCadIndexedColor(92,0,189,0),
new AutoCadIndexedColor(93,126,189,126),
new AutoCadIndexedColor(94,0,129,0),
new AutoCadIndexedColor(95,86,129,86),
new AutoCadIndexedColor(96,0,104,0),
new AutoCadIndexedColor(97,69,104,69),
new AutoCadIndexedColor(98,0,79,0),
new AutoCadIndexedColor(99,53,79,53),
new AutoCadIndexedColor(100,0,255,63),
new AutoCadIndexedColor(101,170,255,191),
new AutoCadIndexedColor(102,0,189,46),
new AutoCadIndexedColor(103,126,189,141),
new AutoCadIndexedColor(104,0,129,31),
new AutoCadIndexedColor(105,86,129,96),
new AutoCadIndexedColor(106,0,104,25),
new AutoCadIndexedColor(107,69,104,78),
new AutoCadIndexedColor(108,0,79,19),
new AutoCadIndexedColor(109,53,79,59),
new AutoCadIndexedColor(110,0,255,127),
new AutoCadIndexedColor(111,170,255,212),
new AutoCadIndexedColor(112,0,189,94),
new AutoCadIndexedColor(113,126,189,157),
new AutoCadIndexedColor(114,0,129,64),
new AutoCadIndexedColor(115,86,129,107),
new AutoCadIndexedColor(116,0,104,52),
new AutoCadIndexedColor(117,69,104,86),
new AutoCadIndexedColor(118,0,79,39),
new AutoCadIndexedColor(119,53,79,66),
new AutoCadIndexedColor(120,0,255,191),
new AutoCadIndexedColor(121,170,255,234),
new AutoCadIndexedColor(122,0,189,141),
new AutoCadIndexedColor(123,126,189,173),
new AutoCadIndexedColor(124,0,129,96),
new AutoCadIndexedColor(125,86,129,118),
new AutoCadIndexedColor(126,0,104,78),
new AutoCadIndexedColor(127,69,104,95),
new AutoCadIndexedColor(128,0,79,59),
new AutoCadIndexedColor(129,53,79,73),
new AutoCadIndexedColor(130,0,255,255),
new AutoCadIndexedColor(131,170,255,255),
new AutoCadIndexedColor(132,0,189,189),
new AutoCadIndexedColor(133,126,189,189),
new AutoCadIndexedColor(134,0,129,129),
new AutoCadIndexedColor(135,86,129,129),
new AutoCadIndexedColor(136,0,104,104),
new AutoCadIndexedColor(137,69,104,104),
new AutoCadIndexedColor(138,0,79,79),
new AutoCadIndexedColor(139,53,79,79),
new AutoCadIndexedColor(140,0,191,255),
new AutoCadIndexedColor(141,170,234,255),
new AutoCadIndexedColor(142,0,141,189),
new AutoCadIndexedColor(143,126,173,189),
new AutoCadIndexedColor(144,0,96,129),
new AutoCadIndexedColor(145,86,118,129),
new AutoCadIndexedColor(146,0,78,104),
new AutoCadIndexedColor(147,69,95,104),
new AutoCadIndexedColor(148,0,59,79),
new AutoCadIndexedColor(149,53,73,79),
new AutoCadIndexedColor(150,0,127,255),
new AutoCadIndexedColor(151,170,212,255),
new AutoCadIndexedColor(152,0,94,189),
new AutoCadIndexedColor(153,126,157,189),
new AutoCadIndexedColor(154,0,64,129),
new AutoCadIndexedColor(155,86,107,129),
new AutoCadIndexedColor(156,0,52,104),
new AutoCadIndexedColor(157,69,86,104),
new AutoCadIndexedColor(158,0,39,79),
new AutoCadIndexedColor(159,53,66,79),
new AutoCadIndexedColor(160,0,63,255),
new AutoCadIndexedColor(161,170,191,255),
new AutoCadIndexedColor(162,0,46,189),
new AutoCadIndexedColor(163,126,141,189),
new AutoCadIndexedColor(164,0,31,129),
new AutoCadIndexedColor(165,86,96,129),
new AutoCadIndexedColor(166,0,25,104),
new AutoCadIndexedColor(167,69,78,104),
new AutoCadIndexedColor(168,0,19,79),
new AutoCadIndexedColor(169,53,59,79),
new AutoCadIndexedColor(170,0,0,255),
new AutoCadIndexedColor(171,170,170,255),
new AutoCadIndexedColor(172,0,0,189),
new AutoCadIndexedColor(173,126,126,189),
new AutoCadIndexedColor(174,0,0,129),
new AutoCadIndexedColor(175,86,86,129),
new AutoCadIndexedColor(176,0,0,104),
new AutoCadIndexedColor(177,69,69,104),
new AutoCadIndexedColor(178,0,0,79),
new AutoCadIndexedColor(179,53,53,79),
new AutoCadIndexedColor(180,63,0,255),
new AutoCadIndexedColor(181,191,170,255),
new AutoCadIndexedColor(182,46,0,189),
new AutoCadIndexedColor(183,141,126,189),
new AutoCadIndexedColor(184,31,0,129),
new AutoCadIndexedColor(185,96,86,129),
new AutoCadIndexedColor(186,25,0,104),
new AutoCadIndexedColor(187,78,69,104),
new AutoCadIndexedColor(188,19,0,79),
new AutoCadIndexedColor(189,59,53,79),
new AutoCadIndexedColor(190,127,0,255),
new AutoCadIndexedColor(191,212,170,255),
new AutoCadIndexedColor(192,94,0,189),
new AutoCadIndexedColor(193,157,126,189),
new AutoCadIndexedColor(194,64,0,129),
new AutoCadIndexedColor(195,107,86,129),
new AutoCadIndexedColor(196,52,0,104),
new AutoCadIndexedColor(197,86,69,104),
new AutoCadIndexedColor(198,39,0,79),
new AutoCadIndexedColor(199,66,53,79),
new AutoCadIndexedColor(200,191,0,255),
new AutoCadIndexedColor(201,234,170,255),
new AutoCadIndexedColor(202,141,0,189),
new AutoCadIndexedColor(203,173,126,189),
new AutoCadIndexedColor(204,96,0,129),
new AutoCadIndexedColor(205,118,86,129),
new AutoCadIndexedColor(206,78,0,104),
new AutoCadIndexedColor(207,95,69,104),
new AutoCadIndexedColor(208,59,0,79),
new AutoCadIndexedColor(209,73,53,79),
new AutoCadIndexedColor(210,255,0,255),
new AutoCadIndexedColor(211,255,170,255),
new AutoCadIndexedColor(212,189,0,189),
new AutoCadIndexedColor(213,189,126,189),
new AutoCadIndexedColor(214,129,0,129),
new AutoCadIndexedColor(215,129,86,129),
new AutoCadIndexedColor(216,104,0,104),
new AutoCadIndexedColor(217,104,69,104),
new AutoCadIndexedColor(218,79,0,79),
new AutoCadIndexedColor(219,79,53,79),
new AutoCadIndexedColor(220,255,0,191),
new AutoCadIndexedColor(221,255,170,234),
new AutoCadIndexedColor(222,189,0,141),
new AutoCadIndexedColor(223,189,126,173),
new AutoCadIndexedColor(224,129,0,96),
new AutoCadIndexedColor(225,129,86,118),
new AutoCadIndexedColor(226,104,0,78),
new AutoCadIndexedColor(227,104,69,95),
new AutoCadIndexedColor(228,79,0,59),
new AutoCadIndexedColor(229,79,53,73),
new AutoCadIndexedColor(230,255,0,127),
new AutoCadIndexedColor(231,255,170,212),
new AutoCadIndexedColor(232,189,0,94),
new AutoCadIndexedColor(233,189,126,157),
new AutoCadIndexedColor(234,129,0,64),
new AutoCadIndexedColor(235,129,86,107),
new AutoCadIndexedColor(236,104,0,52),
new AutoCadIndexedColor(237,104,69,86),
new AutoCadIndexedColor(238,79,0,39),
new AutoCadIndexedColor(239,79,53,66),
new AutoCadIndexedColor(240,255,0,63),
new AutoCadIndexedColor(241,255,170,191),
new AutoCadIndexedColor(242,189,0,46),
new AutoCadIndexedColor(243,189,126,141),
new AutoCadIndexedColor(244,129,0,31),
new AutoCadIndexedColor(245,129,86,96),
new AutoCadIndexedColor(246,104,0,25),
new AutoCadIndexedColor(247,104,69,78),
new AutoCadIndexedColor(248,79,0,19),
new AutoCadIndexedColor(249,79,53,59),
new AutoCadIndexedColor(250,51,51,51),
new AutoCadIndexedColor(251,80,80,80),
new AutoCadIndexedColor(252,105,105,105),
new AutoCadIndexedColor(253,130,130,130),
new AutoCadIndexedColor(254,190,190,190),
new AutoCadIndexedColor(255,255,255,255),
                };
            }
        }

        private Point3D64D ColorCoordinates
        {
            get
            {
                return new Point3D64D(this.R, this.G, this.B);
            }
        }
    }
}
